package com.hundsun.cprs.yyt.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.hundsun.cprs.yyt.service.match.core.TradeCenter;
import com.hundsun.cprs.yyt.service.match.dto.EntrustRequest;
import com.hundsun.cprs.yyt.service.match.service.TradeMatchInnerService;

@Controller
public class StockAction {

    @Autowired
    private TradeMatchInnerService tradeMatchService;
    
    /**
     * 入口,显示所有本地处理的份额信息
     * 
     * @param model
     */
    @RequestMapping("/stock/all.htm")
    public void all(@RequestParam(value = "code", required = false) String code, ModelMap model) {
        List<TradeCenter> cs = new ArrayList<TradeCenter>();
        if (StringUtils.isBlank(code)) {
            for (TradeCenter tc : tradeMatchService.getHandleTradeCenters()) {
                 cs.add(tc);
            }
            model.put("tradeCenters", cs);
        } else {
            code = code.trim();
            for (TradeCenter tc : tradeMatchService.getHandleTradeCenters()) {
                if (tc.getStockCode().indexOf(code) != -1) {
                   cs.add(tc);
                }
            }
            model.put("tradeCenters", cs);
            model.put("code", code);
        }
    }
    
    @RequestMapping("/stock/reInit.htm")
    public void reInit(@RequestParam(value = "code") String code){
        tradeMatchService.reInitTradeCenter(code);
    }
}
